<?php
session_start();
define("ROOT_PATH",$_SESSION['path']);
require_once ROOT_PATH .'/lib/models/hrfunct/EmpAttach.php';
require_once ROOT_PATH .'/lib/confs/Conf.php';    
if(isset($_GET['id'])&& isset($_GET['ATTACH'])){
    download();
}else{
    $conf = new Conf();               
    mysql_connect($conf->dbhost,$conf->dbuser,$conf->dbpass);
    mysql_select_db($conf->dbname);
    $employees = @mysql_query("SELECT * FROM hs_hr_employee where  emp_status != 'EST000'");
    while ($employee = mysql_fetch_array($employees)) {
       $empAtts = @mysql_query("SELECT * FROM hs_hr_emp_attachment where  emp_number = '".$employee['emp_number']."'");   
       while ($empAtt = mysql_fetch_array($empAtts)) {
           $link = 'http://intranet.s3corp.com.vn/download.php?id='.$employee['emp_number'].'&ATTACH='.$empAtt['eattach_id'].'&NAME='.$employee["emp_lastname"]."_".$employee["emp_middle_name"]."_".$employee['emp_firstname']; 
           echo "<a  href='".$link."'>".$employee["emp_lastname"]." ".$employee["emp_middle_name"]." ".$employee['emp_firstname']."</a><br>" ;
       } 
    }
    
}
function download(){
    $attachment = new EmpAttach();
    $arr[0]=$_GET['id'];
    $arr[1]=$_GET['ATTACH'];
    $name = $_GET['NAME'];
    $edit=$attachment->filterEmpAtt($arr);
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private", false);
    header("Content-Type: " .$edit[0][6]);
    header("Content-Disposition: attachment; filename=\"".$name.'_'.$arr[1].'_'.$edit[0][3]."\";");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " .$edit[0][4]);
    echo $edit[0][5];
}
?>
